package com.zhht.htzx.model;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * 订单数据模型
 */
public class Order implements Serializable {
    
    public enum OrderStatus {
        PENDING("待付款", 0),
        PAID("已付款", 1),
        SHIPPED("已发货", 2),
        DELIVERED("已送达", 3),
        COMPLETED("已完成", 4),
        CANCELLED("已取消", 5),
        REFUNDING("退款中", 6),
        REFUNDED("已退款", 7);
        
        private String displayName;
        private int code;
        
        OrderStatus(String displayName, int code) {
            this.displayName = displayName;
            this.code = code;
        }
        
        public String getDisplayName() {
            return displayName;
        }
        
        public int getCode() {
            return code;
        }
        
        public static OrderStatus fromCode(int code) {
            for (OrderStatus status : values()) {
                if (status.code == code) {
                    return status;
                }
            }
            return PENDING;
        }
    }
    
    private String orderId;           // 订单ID
    private String userId;            // 用户ID
    private List<OrderItem> items;    // 订单商品列表
    private double totalAmount;       // 订单总金额
    private double discountAmount;    // 优惠金额
    private double actualAmount;      // 实付金额
    private OrderStatus status;       // 订单状态
    private String address;           // 收货地址
    private String receiverName;      // 收货人姓名
    private String receiverPhone;     // 收货人电话
    private String remark;            // 订单备注
    private Date createTime;          // 创建时间
    private Date updateTime;          // 更新时间
    private Date payTime;             // 支付时间
    private Date shipTime;            // 发货时间
    private Date deliveryTime;        // 送达时间
    private String trackingNumber;    // 快递单号
    private String trackingCompany;   // 快递公司
    
    // 构造函数
    public Order() {}
    
    public Order(String orderId, String userId, List<OrderItem> items, double totalAmount) {
        this.orderId = orderId;
        this.userId = userId;
        this.items = items;
        this.totalAmount = totalAmount;
        this.actualAmount = totalAmount;
        this.status = OrderStatus.PENDING;
        this.createTime = new Date();
        this.updateTime = new Date();
    }
    
    // Getter和Setter方法
    public String getOrderId() {
        return orderId;
    }
    
    public void setOrderId(String orderId) {
        this.orderId = orderId;
    }
    
    public String getUserId() {
        return userId;
    }
    
    public void setUserId(String userId) {
        this.userId = userId;
    }
    
    public List<OrderItem> getItems() {
        return items;
    }
    
    public void setItems(List<OrderItem> items) {
        this.items = items;
    }
    
    public double getTotalAmount() {
        return totalAmount;
    }
    
    public void setTotalAmount(double totalAmount) {
        this.totalAmount = totalAmount;
    }
    
    public double getDiscountAmount() {
        return discountAmount;
    }
    
    public void setDiscountAmount(double discountAmount) {
        this.discountAmount = discountAmount;
    }
    
    public double getActualAmount() {
        return actualAmount;
    }
    
    public void setActualAmount(double actualAmount) {
        this.actualAmount = actualAmount;
    }
    
    public OrderStatus getStatus() {
        return status;
    }
    
    public void setStatus(OrderStatus status) {
        this.status = status;
        this.updateTime = new Date();
    }
    
    public String getAddress() {
        return address;
    }
    
    public void setAddress(String address) {
        this.address = address;
    }
    
    public String getReceiverName() {
        return receiverName;
    }
    
    public void setReceiverName(String receiverName) {
        this.receiverName = receiverName;
    }
    
    public String getReceiverPhone() {
        return receiverPhone;
    }
    
    public void setReceiverPhone(String receiverPhone) {
        this.receiverPhone = receiverPhone;
    }
    
    public String getRemark() {
        return remark;
    }
    
    public void setRemark(String remark) {
        this.remark = remark;
    }
    
    public Date getCreateTime() {
        return createTime;
    }
    
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
    
    public Date getUpdateTime() {
        return updateTime;
    }
    
    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }
    
    public Date getPayTime() {
        return payTime;
    }
    
    public void setPayTime(Date payTime) {
        this.payTime = payTime;
    }
    
    public Date getShipTime() {
        return shipTime;
    }
    
    public void setShipTime(Date shipTime) {
        this.shipTime = shipTime;
    }
    
    public Date getDeliveryTime() {
        return deliveryTime;
    }
    
    public void setDeliveryTime(Date deliveryTime) {
        this.deliveryTime = deliveryTime;
    }
    
    public String getTrackingNumber() {
        return trackingNumber;
    }
    
    public void setTrackingNumber(String trackingNumber) {
        this.trackingNumber = trackingNumber;
    }
    
    public String getTrackingCompany() {
        return trackingCompany;
    }
    
    public void setTrackingCompany(String trackingCompany) {
        this.trackingCompany = trackingCompany;
    }
    
    // 获取商品总数
    public int getTotalItemCount() {
        if (items == null) return 0;
        int count = 0;
        for (OrderItem item : items) {
            count += item.getQuantity();
        }
        return count;
    }
    
    // 获取订单状态显示文本
    public String getStatusDisplayText() {
        return status.getDisplayName();
    }
    
    // 是否可以取消订单
    public boolean canCancel() {
        return status == OrderStatus.PENDING || status == OrderStatus.PAID;
    }
    
    // 是否可以申请退款
    public boolean canRefund() {
        return status == OrderStatus.PAID || status == OrderStatus.SHIPPED || 
               status == OrderStatus.DELIVERED || status == OrderStatus.COMPLETED;
    }
    
    // 是否可以确认收货
    public boolean canConfirmDelivery() {
        return status == OrderStatus.DELIVERED;
    }
} 